package com.hzhr.iot.user.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.user.dao.RoleDao;
import com.hzhr.iot.user.entity.RoleEntity;
import com.hzhr.iot.user.queryModel.custom.RoleCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class RoleDaoHelper {
    @Autowired
    RoleDao roleDao;

    public RoleEntity getById(int id) {
        RoleCustomQueryModel queryModel = new RoleCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        RoleEntity roleEntity = roleDao.selectEntity(queryModel);
        return roleEntity;
    }

    public RoleEntity getByNameAndCompanyId(String name, int companyId) {
        if (name == null) return null;
        RoleCustomQueryModel queryModel = new RoleCustomQueryModel();
        queryModel.setEqual_name(name);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        RoleEntity roleEntity = roleDao.selectEntity(queryModel);
        return roleEntity;
    }

    public int getCountByNameAndCompanyId(String name, int companyId) {
        if (name == null) return 0;
        RoleCustomQueryModel queryModel = new RoleCustomQueryModel();
        queryModel.setEqual_name(name);
        queryModel.setEqual_companyId(companyId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        int count = roleDao.selectCount(queryModel);
        return count;
    }


}
